﻿#pragma once
#include "Common.h"


class algorithm_base : public QObject
{
	Q_OBJECT
public:
	algorithm_base();
	~algorithm_base();

	virtual void init() = 0;

	virtual int pustImage(IMG_DATA);

	virtual void execute(QSharedPointer<IMG_DATA> pData, int nBufferSize ) = 0;

public:
	QThreadPool					m_ThreadPool;

	// 用原子变量省去加锁
	std::atomic_int				m_nThreadState;

	QReadWriteLock   			m_ImageQueue_lock_;
	// 使用智能指针自动管理对象
	QQueue<QSharedPointer<IMG_DATA>>  m_ImageQueue;



	QMutex									mutex;


	QImage urlToPixmap(QString url);

	void saveImage(IMG_DATA data);

	void pushKafka(QString strTopc, QString strJson, QString strStationId);

	void saveImage(cv::Mat mat, QString strPrjName, IMG_DATA data, int nState);

	void stop();

signals:
	void updateShow(int nId, QImage img, int nBuffersize);
};

// Save的执行线程体
class _Thread : public QObject, public QRunnable
{
	Q_OBJECT
public:

	_Thread(algorithm_base* pDlg)
	{
		this->m_pDlg = pDlg;
	};

	~_Thread() {};
protected:
	// 线程函数
	virtual void run();

private:
	algorithm_base* m_pDlg;
};

